#!/bin/sh
if [ -f $1.s2c ]
then
   rm $1.s2c
fi

echo " " >>$1.s2c
echo " is_dynamic_sql = TRUE;" >>$1.s2c
echo "   is_plsql_block = TRUE;" >>$1.s2c
echo "   log_sql_exec = TRUE;" >>$1.s2c
echo "   log_row_count = TRUE;" >>$1.s2c
echo "   sql_error_exit = TRUE;" >>$1.s2c
echo "   step_as_trans = FALSE;" >>$1.s2c
echo "   memset(sql_step_name, 0, 1025);" >>$1.s2c
echo "   strncpy(sql_step_name, "Unnamed-Step-#03.2 ", 1024);" >>$1.s2c
echo "   do_before_run_sql();" >>$1.s2c
echo "   // ---- Oracle PL/SQL block - BEGIN -----" >>$1.s2c
echo " " >>$1.s2c
echo " //char *dynasql;" >>$1.s2c
echo " //if(dynasql) free(dynasql);" >>$1.s2c
echo " dynasql = malloc(100000);" >>$1.s2c
echo " " >>$1.s2c
echo " " >>$1.s2c
cat $1  >>$1.s2c
sed -i "s/String(/strcat(dynasql,/g" $1.s2c
sed -i "s/) +/);/g" $1.s2c
echo " " >>$1.s2c
echo " " >>$1.s2c

echo " EXEC SQL AT :orcl_svr_var_name PREPARE Stmt FROM :dynasql;" >>$1.s2c
echo " EXEC SQL AT :orcl_svr_var_name EXECUTE Stmt USING :proc_PAR_DATE,:proc_PAR_DATE,:proc_PAR_DATE ,:proc_PAR_DATE ;" >>$1.s2c
echo " " >>$1.s2c
echo " " >>$1.s2c
echo " " >>$1.s2c
echo "   // ---- Oracle PL/SQL block -  END  -----" >>$1.s2c
echo "   if(dynasql) free(dynasql);" >>$1.s2c
echo "   rst = do_after_run_sql();" >>$1.s2c
echo "   if (rst != MY_EC_OK) return rst;" >>$1.s2c
echo " " >>$1.s2c
echo " " >>$1.s2c
